package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.Annex;
import com.ruoyi.system.api.service.IAnnexService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags="附件信息")
@RestController
@RequestMapping("/api/cc/service/annex/")
public class AnnexController extends BaseController {

    @Autowired
    private IAnnexService annexService;

    private static final Logger log = LoggerFactory.getLogger(AnnexController.class);
    /**
     *  根据附件id 批量删除附件信息
     *
     * @param id
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020-03-03 16:57
     */
    @Log(title = "根据附件id 删除附件信息", businessType = BusinessType.DELETE)
    @GetMapping("deleteAnnexById")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "根据附件id 删除附件信息", httpMethod = "GET", notes = "根据附件id 批量删除附件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "附件id", name = "id", required = true, dataType = "String", paramType = "query", example = "1")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> deleteAnnexById(@RequestParam String id) {
        try {
            if (StringUtils.isEmpty(id)) {
                return new ResponseWithData().error("id cannot be empty");
            }
            annexService.deleteAnnexById(Long.parseLong(id));
            return new ResponseWithData<>().success("删除成功！").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常！").code(500);
        }
    }

    /**
     *  查询报告附件信息
     *
     * @param serviceNo serviceNo
     * @param helpId 辅助id
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020-03-03 16:10
     */
    @GetMapping("selectReportPortAnnexs")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询报告附件信息", httpMethod = "GET", notes = "查询报告附件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "辅助id", name = "helpId", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectReportPortAnnexs(@RequestParam(value="serviceNo",required=true) String serviceNo,
                                                      @RequestParam(value="helpId",required=true) String helpId) {
        try {
            return annexService.selectAnnexsByServiceNoAndHelpId(serviceNo, helpId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  服务报告附件上传 单文件上传
     *
     * @param file
     * @param request
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/12 3:45 下午
     */
    @Log(title = "服务报告附件上传 单文件上传", businessType = BusinessType.IMPORT)
    @PostMapping("uploadFile")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "服务报告附件上传", httpMethod = "POST", notes = "服务报告附件上传")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功" )
    })
    public ResponseWithData<?> uploadFile(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request){
        try {
            return annexService.uploadFile(file, request);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     *  三个报告附件上传
     *
     * @param file
     * @param request
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author sunjy
     * @date 2020年4月1日12:30:29
     */
    @Log(title = "三个报告附件上传", businessType = BusinessType.IMPORT)
    @PostMapping("uploadFileReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "三个报告附件上传", httpMethod = "POST", notes = "三个报告附件上传")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功" )
    })
    public ResponseWithData<?> uploadFileReport(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request){
        try {
            return annexService.uploadFileReport(file, request);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  备件还货附件上传
     *
     * @param file
     * @param request
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author wlf
     * @date 2020年4月8日10:37:29
     */
    @Log(title = "备件还货附件上传", businessType = BusinessType.IMPORT)
    @PostMapping("uploadFileParts")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "备件还货附件上传", httpMethod = "POST", notes = "备件还货附件上传")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功" )
    })
    public ResponseWithData<?> uploadFileParts(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request){
        try {
            return annexService.uploadFileParts(file, request);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  三个报告附件上传(直接调cc)
     *
     * @param file
     * @param request
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author wlf
     * @date 2020年4月10日15:49:29
     */
    @Log(title = "三个报告附件上传(直接调cc)", businessType = BusinessType.IMPORT)
    @PostMapping("uploadWorkReportPic")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "三个报告附件上传", httpMethod = "POST", notes = "三个报告附件上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enginner_id", value = "工程师id", required = true, dataType="String") ,
            @ApiImplicitParam(name = "service_no", value = "服务号", required = true, dataType="String"),
            @ApiImplicitParam(name = "helpId", value = "附件标识（1.工作报告; 2.签字验收报告; 3.客户现场确认单）", required = true, dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功" )
    })
    public ResponseWithData<?> uploadWorkReportPic(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request){
        try {
            return annexService.uploadWorkReportPic(file, request);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     *  报告图片查询列表
     *
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author wlf
     * @date 2020年4月10日15:49:29
     */
    @PostMapping("reportPicList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "三个报告附件上传", httpMethod = "GET", notes = "三个报告附件上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enginner_id", value = "工程师id", required = true, dataType="String") ,
            @ApiImplicitParam(name = "service_no", value = "服务号", required = true, dataType="String"),
            @ApiImplicitParam(name = "helpId", value = "附件标识（1.工作报告; 2.签字验收报告; 3.客户现场确认单）", required = true, dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功" )
    })
    public ResponseWithData<?> reportPicList(
            @RequestParam(value="enginner_id",required=true) String enginner_id,
            @RequestParam(value="service_no",required=true) String service_no,
            @RequestParam(value="helpId",required=true) Long helpId
      ){
        try {
            Annex annex=new Annex();
            annex.setEnginnerId(enginner_id);
            annex.setServiceNo(service_no);
            annex.setHelpId(helpId.toString());
            List<Annex> annexList= annexService.selectAnnexList(annex);
            return new ResponseWithData<>().success(annexList).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     *  报告图片查询列表
     *
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author wlf
     * @date 2020年4月10日15:49:29
     */
    @GetMapping("/reportPicList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "三个报告附件上传", httpMethod = "GET", notes = "三个报告附件上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enginner_id", value = "工程师id", required = true, dataType="String") ,
            @ApiImplicitParam(name = "service_no", value = "服务号", required = true, dataType="String"),
            @ApiImplicitParam(name = "helpId", value = "附件标识（1.工作报告; 2.签字验收报告; 3.客户现场确认单）", required = true, dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功" )
    })
    public ResponseWithData<?> reportPicList(
            @RequestParam(value="enginner_id",required=true) String enginner_id,
            @RequestParam(value="service_no",required=true) String service_no,
            @RequestParam(value="helpId",required=true) String helpId
    ){
        try {
            Annex annex=new Annex();
            annex.setEnginnerId(enginner_id);
            annex.setServiceNo(service_no);
            annex.setHelpId(helpId);
            List<Annex> annexList= annexService.selectAnnexList(annex);
            return new ResponseWithData<>().success(annexList).msg("查询成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     *  删除图片查询列表
     *
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author wlf
     * @date 2020年4月10日15:49:29
     */
    @Log(title = "删除附件信息", businessType = BusinessType.DELETE)
    @GetMapping("/deleteAnnexByIds")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "删除附件信息", httpMethod = "GET", notes = "删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "附件id", required = true, dataType="String")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功" )
    })
    public ResponseWithData<?> deleteAnnexByIds(
            @RequestParam(value="ids",required=true) String ids
    ){
        try {
            annexService.deleteAnnexByIds(ids);
            return new ResponseWithData<>().success().msg("删除成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    
    
    
    /**
     * 2.76	获取服务通知工作报告附件，签字验收报告附件，客户现场确认单
     * @param service_no
     * @return
     */
    @GetMapping("getServiceFileHandle")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取服务工作报告附件", httpMethod = "GET", notes = "获取服务工作报告附件")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getServiceFileHandle(@RequestParam(value="serviceNo",required=true) String serviceNo){
    	
    	 try {
    		 return annexService.getServiceFileHandle(serviceNo);
         } catch (Exception e) {
             log.error("程序异常", e.getMessage());
             return new ResponseWithData().error().msg("系统异常").code(500);
         }
    }
    /**
     *2.77	获取服务通知关联合同信息接口
     * @param service_no
     * @return
     */
    @GetMapping("getServiceContractHandle")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取服务通知关联合同信息接口", httpMethod = "GET", notes = "获取服务通知关联合同信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getServiceContractHandle(@RequestParam(value="serviceNo",required=true) String serviceNo){

        try {
            return annexService.getServiceContractHandle(serviceNo);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
}
